<?php
function cleanValue($val){
	if ($val == "") return "";
	$val = str_replace( "&#032;", " ", $val );
	$val = str_replace( chr(0xCA), "", $val );  //Remove sneaky spaces
	$val = str_replace( "'", "&#39;", $val ); // IMPORTANT: It helps to increase sql query safety.
	// Ensure unicode chars are OK
	$val = preg_replace("/&amp;#([0-9]+);/s", "&#\\1;", $val );
	// Strip slashes if not already done so.
	if ( get_magic_quotes_gpc() ){
		$val = stripslashes($val);
	}
	// Swop user inputted backslashes
	return $val;
}